package com.nuaa.ange.controller;


import com.nuaa.ange.annotation.ApiLog;
import com.nuaa.ange.common.lang.RespBean;
import com.nuaa.ange.entity.ScanHistory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * @description
 * @author 玦离
 * @date 2023/1/2 21:41
 */

@RestController
@Api(tags = "浏览历史相关接口")
@RequestMapping("/scan-history")
public class ScanHistoryController extends BaseController{

    @ApiOperation(value = "浏览文章")
    @PostMapping("/saveOrUpdate")
    @ApiLog
    public RespBean saveOrUpdateScanHistory(@RequestBody ScanHistory scanHistory) {
        scanHistory.setUserId(getProfileId());
        // TODO: 2023/1/4 能否保存或者更新，更新时间是否会变，这里有问题，不是主键
        scanHistoryService.saveOrUpdate(scanHistory);
        return RespBean.ok("一条浏览记录已保存/更新");
    }

    @ApiOperation(value = "删除指定浏览记录")
    @GetMapping("/delete")
    @ApiLog
    public RespBean deleteScanHistory(@RequestParam("scanId") int scanId) {
        scanHistoryService.removeById(scanId);
        return RespBean.ok("一条浏览记录已删除");
    }
}
